<!--
 * @Description: 管辖运营情况
 * @Author: Huang Junjie
 * @Date: 2021-10-19 11:27:04
 * @LastEditTime: 2021-10-20 20:34:38
 * @LastEditors: Huang Junjie
-->
<template>
  <div class="content-card">
    <!-- 标题 -->
    <div class="title">管辖运营情况</div>
    <!-- 标题 -->

    <!-- 组织机构统计 -->
    <div class="subtitle">
      组织机构统计
      <i class="el-icon-more" />
    </div>
    <div class="num-card">
      <div class="item">
        <div>供电段</div>
        <div class="num">{{ statisticsData.gdds }}</div>
      </div>
      <div class="item">
        <div>车间</div>
        <div class="num">{{ statisticsData.workShops }}</div>
      </div>
      <div class="item-last">
        <div>班组</div>
        <div class="num">{{ statisticsData.workAreas }}</div>
      </div>
    </div>
    <!-- 组织机构统计 -->

    <!-- 总运营里程 -->
    <div class="subtitle">
      总运营里程
      <i class="el-icon-more" />
    </div>
    <div class="num-card">
      <div class="item">
        <div>高铁运营里程</div>
        <div class="num">{{ statisticsData.gtMileage }}</div>
      </div>
      <div class="item-last">
        <div>普铁运营里程</div>
        <div class="num">{{ statisticsData.ptMileage }}</div>
      </div>
    </div>
    <!-- 总运营里程 -->

    <!-- 总管辖线路 -->
    <div class="subtitle">
      总管辖线路
      <i class="el-icon-more" />
    </div>
    <div class="num-card">
      <div class="item">
        <div>高铁管辖线路</div>
        <div class="num">{{ statisticsData.gtLines }}</div>
      </div>
      <div class="item-last">
        <div>普铁管辖线路</div>
        <div class="num">{{ statisticsData.ptLines }}</div>
      </div>
    </div>
    <!-- 总管辖线路 -->
  </div>
</template>

<script>
import {
  getOrganizationStatistics,
  getOperationUnderJurisdictionStatistics,
  getOperationUnderJurisdictionStatisticsDj
} from '@/api/jjxt/data-center-home';
import { mapGetters } from 'vuex';

export default {
  name: 'OperationUnderJurisdiction',
  props: {
    unitCodeParams: {
      type: String,
      default() {
        return '';
      }
    },
    mCode: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      // 统计数据
      statisticsData: {
        gdds: 0,
        workShops: 0,
        workAreas: 0,
        gtMileage: 0,
        ptMileage: 0,
        gtLines: 0,
        ptLines: 0
      }
    };
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  watch: {
    unitCodeParams() {
      this.statisticsData = {
        gdds: 0,
        workShops: 0,
        workAreas: 0,
        gtMileage: 0,
        ptMileage: 0,
        gtLines: 0,
        ptLines: 0
      };
      this.getOrganizationStatistics(); // 查询组织机构统计
      // if：供电部账号登录
      if (this.unitCodeParams === 'gd') {
        this.getOperationUnderJurisdictionStatistics(); // 查询总运营、总管辖情况（局级）
      } else if (this.unitCodeParams !== '') {
        this.getOperationUnderJurisdictionStatisticsDj(); // 查询总运营、总管辖情况（段级）
      }
    }
  },
  methods: {
    // 查询组织机构统计
    getOrganizationStatistics() {
      // 查询组织机构统计
      getOrganizationStatistics().then(response => {
        this.statisticsData.gdds = response.data.gdds.toLocaleString();
        this.statisticsData.workShops = response.data.workShops.toLocaleString();
        this.statisticsData.workAreas = response.data.workAreas.toLocaleString();
      });
    },

    // 查询总运营、总管辖情况（局级）
    getOperationUnderJurisdictionStatistics() {
      // 查询总运营、总管辖情况（局级）
      getOperationUnderJurisdictionStatistics().then(response => {
        this.statisticsData.gtMileage = response.data.gtMileage.toLocaleString();
        this.statisticsData.ptMileage = response.data.ptMileage.toLocaleString();
        this.statisticsData.gtLines = response.data.gtLines.toLocaleString();
        this.statisticsData.ptLines = response.data.ptLines.toLocaleString();
      });
    },

    // 查询总运营、总管辖情况（段级）
    getOperationUnderJurisdictionStatisticsDj() {
      // 查询总运营、总管辖情况（段级）
      getOperationUnderJurisdictionStatisticsDj({
        unitCodeParams: this.unitCodeParams,
        deptNo: this.mCode
      }).then(response => {
        this.statisticsData.gtMileage = response.data.gtMileage.toLocaleString();
        this.statisticsData.ptMileage = response.data.ptMileage.toLocaleString();
        this.statisticsData.gtLines = response.data.gtLines.toLocaleString();
        this.statisticsData.ptLines = response.data.ptLines.toLocaleString();
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.content-card {
  width: 355px;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid #ebebeb;
  .title {
    color: #666666;
    padding: 5px 0 5px 10px;
    font-weight: 600;
    border-bottom: 1px solid #ebebeb;
  }
  .subtitle {
    font-size: 14px;
    color: #676767;
    padding: 5px 0 5px 10px;
    border-top: 1px solid #ebebeb;
    border-bottom: 1px solid #ebebeb;
    .el-icon-more {
      float: right;
      margin-right: 10px;
      cursor: pointer;
    }
    .el-icon-more:hover {
      color: #54B2FC;
      float: right;
      margin-right: 10px;
      cursor: pointer;
    }
  }
  .num-card {
    font-size: 12px;
    color: #676767;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    .item {
      width: 200px;
      line-height: 22px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border-right: 1px solid #ebebeb;
      .num {
        color: #666666;
        font-size: 20px;
        font-weight: 600;
      }
      .num:hover {
        color: #54B2FC;
        text-decoration: underline;
        cursor: pointer;
      }
    }
    .item-last {
      width: 200px;
      line-height: 22px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .num {
        color: #666666;
        font-size: 20px;
        font-weight: 600;
        cursor: pointer;
      }
      .num:hover {
        color: #54B2FC;
        text-decoration: underline;
        cursor: pointer;
      }
    }
  }
}
</style>
